package com.zhangjianling.premp.controller.sys;

import com.zhangjianling.premp.controller.base.BaseController;
import com.zhangjianling.premp.entity.sys.ResultEntity;
import com.zhangjianling.premp.entity.sys.SysBaseInfo;
import com.zhangjianling.premp.server.sys.BaseInfoService;
import com.zhangjianling.premp.utils.SystemAopLog;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 基本信息配置表
 * @author zhangjl
 *
 */
@RestController
@RequestMapping("baseInfo")
public class BaseInfoController extends BaseController {
	@Resource
	private BaseInfoService baseInfoService;
	
	@GetMapping("getDetail")
	public ResultEntity getDetail(){
		ResultEntity res = new ResultEntity();
		try{
			SysBaseInfo baseInfo = baseInfoService.getDetail();
			res.setData(baseInfo);
			res.setMessage(GET_SUCCESS);
			res.setCode(SUCCESS);
		}catch(Exception e){
			e.printStackTrace();
			res.setMessage(GET_ERROR + ":" + e.getMessage());
			res.setCode(ERROR);
		}
		return res;
	}
	
	@SystemAopLog(description = "基本信息保存")
	@PostMapping("saveBase")
	public ResultEntity saveBase(SysBaseInfo baseInfo){
		ResultEntity res = new ResultEntity();
		try{
			baseInfoService.save(baseInfo);
			res.setMessage(OPERATE_SUCCESS);
			res.setCode(SUCCESS);
		}catch(Exception e){
			e.printStackTrace();
			res.setMessage(OPERATE_ERROR + ":" + e.getMessage());
			res.setCode(ERROR);
		}
		return res;
	}
}
